package cn.shengongying.api.dto;

import cn.shengongying.bean.BaseUser;
import cn.shengongying.model.BossCompanyCard;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * author: RXK
 * date: 2022/1/7 星期五
 * desc:
 */
@Getter
@Setter
public class CompanyCardInDTO {

    @ApiModelProperty(value = "id")
    private Long id;

    /**
     * logo
     */
    @ApiModelProperty(value = "logo")
    private String logo;

    /**
     * 公司简称
     */
    @ApiModelProperty(value = "简称")
    private String shortName;

    /**
     * 公司名称
     */
    @ApiModelProperty(value = "公司名称")
    private String companyName;

    /**
     * 成立日期
     */
    @ApiModelProperty(value = "成立时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date establishedTime;

    /**
     * 公司性质(0:加工商;1:模具商;2:设备商)
     */
    @ApiModelProperty(value = "公司类型(0:加工商;1:模具商;2:设备商)")
    private Integer category;

    /**
     * 公司地址
     */
    @ApiModelProperty(value = "公司地址")
    private String address;

    /**
     * 联系人
     */
    @ApiModelProperty(value = "联系人")
    private String linkMan;

    /**
     * 联系电话
     */
    @ApiModelProperty(value = "联系电话")
    private String mobile;

    /**
     * 公司简介
     */
    @ApiModelProperty(value = "简介")
    private String desc;

    /**
     * 图片
     */
    private String picture;


    public BossCompanyCard build(BaseUser user) {
        BossCompanyCard card = new BossCompanyCard();
        card.setBossId(user.getId());
        boolean change = false;

        if (StringUtils.isNotEmpty(logo)) {
            change = true;
            card.setLogo(this.getLogo());
        }

        if (StringUtils.isNotEmpty(this.companyName)) {
            change = true;
            card.setCompanyName(this.companyName);
        }

        if (StringUtils.isNotEmpty(this.shortName)) {
            change = true;
            card.setShortName(this.shortName);
        }

        if (null != establishedTime) {
            change = true;
            card.setEstablishedTime(this.establishedTime);
        }

        if (null != category) {
            change = true;
            card.setCategory(category);
        }


        if (StringUtils.isNotEmpty(linkMan)) {
            change = true;
            card.setLinkMan(this.linkMan);
        }

        if (StringUtils.isNotEmpty(desc)) {
            change = true;
            card.setDescInfo(desc);
        }

        if (StringUtils.isNotEmpty(mobile)) {
            change = true;
            card.setMobile(mobile);
        }

        if (StringUtils.isNotEmpty(address)) {
            change = true;
            card.setAddress(address);
        }

        if (change) {
            card.setId(this.id);
        }else{
            card = null;
        }
        return card;
    }
}
